Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports System.Xml
Imports System.Collections
Imports System.ComponentModel
Imports System.Runtime.Serialization
Imports System.Security.Permissions
Imports C4F.DevKit.WebServices.Datasets
Imports System.Globalization

Namespace C4F.DevKit.WebServices
	''' <summary>
	''' Exposes search functionality on Amazon.com
	''' </summary>
	<ToolboxItem(True)> _
	Public Class Amazon
		Inherits C4FWebServicesBase
		#Region "Private members"
		''' <summary>
		''' Base Url
		''' </summary>
        Private Shared baseUrl As String = My.Resources.AmazonBaseUrl

		''' <summary>
		''' Application key
		''' </summary>
		Private applicationKey_Renamed As String = String.Empty

		#End Region

		#Region "Accessors"

		''' <summary>
		''' Access Key required to use the Api
		''' </summary>
		<Category("Amazon"), Description("Access Key required to use the Api")> _
		Public Property ApplicationKey() As String
			Get
				If Me.applicationKey_Renamed Is Nothing Then
					Return String.Empty
				Else
					Return Me.applicationKey_Renamed
				End If
			End Get
			Set(ByVal value As String)
				If value Is Nothing Then
					Me.applicationKey_Renamed = String.Empty
				Else
					Me.applicationKey_Renamed = value.Trim()
				End If
			End Set
		End Property
		#End Region

		#Region "Constructors"
		''' <summary>
		''' Initializes a new object of Amazon class
		''' </summary>
		Public Sub New()
		End Sub
		''' <summary>
		''' Initializes a new object of Amazon class with an application key
		''' </summary>
		''' <param name="appKey">Application key</param>
		Public Sub New(ByVal appKey As String)
			Me.ApplicationKey = appKey
		End Sub
		#End Region

		#Region "Public functions"
		''' <summary>
		''' Searches for items based on keyword(s)
		''' </summary>
		''' <param name="searchCategory">Search Category</param>
		''' <param name="pageNo">Search Results page number (null for default value)</param>
		''' <param name="condition">Condition of the item</param>
		''' <param name="minimumPrice">Minimum price (null for default value)</param>
		''' <param name="maximumPrice">Maximum price (null for default value)</param>
		''' <param name="keywords">One or more keywords to search for</param>
		''' <returns>List of Items that match the search criteria</returns>
		''' <exception cref="InvalidOperationException">The Application Key is not set (OR) the keywords are not specified</exception>
		''' <exception cref="AmazonException">Amazon Web service has raised an error</exception>
		Public Function SearchItems(ByVal searchCategory As SearchCategory, ByVal pageNo As Nullable(Of Integer), ByVal condition As ItemCondition, ByVal minimumPrice As Nullable(Of Integer), ByVal maximumPrice As Nullable(Of Integer), ParamArray ByVal keywords As String()) As List(Of AmazonItem)
			If String.IsNullOrEmpty(Me.ApplicationKey) Then
                Throw New InvalidOperationException(My.Resources.ErrorApplicationKeyNotSet)
            End If

            ' Throw an exception if no keywords were specified
            If keywords Is Nothing OrElse keywords.Length = 0 Then
                Throw New InvalidOperationException(String.Format(CultureInfo.InvariantCulture, My.Resources.ErrorSpecifyArgument, "keyword"))
            End If


            Dim requestUrl As String = Me.GetRequestUrl(searchCategory, pageNo, condition, minimumPrice, maximumPrice, GetKeywordString(keywords), Nothing, Nothing, Nothing, Nothing, Nothing)

            ' Get Amazon ItemSearch responses
            Dim responseData As String = MyBase.GetQueryResponse(requestUrl)

            ' Parse the data and return results
            Return Amazon.ParseResponseXml(responseData)
        End Function

        ''' <summary>
        ''' Searches for items based on keyword(s)
        ''' </summary>
        ''' <param name="searchCategory">Search Category</param>
        ''' <param name="keywords">One or more keywords to search for</param>
        ''' <returns>List of Items that match the search criteria</returns>
        ''' <exception cref="InvalidOperationException">The Application Key is not set (OR) the keywords are not specified</exception>
        ''' <exception cref="AmazonException">Amazon Web service has raised an error</exception>
        Public Function SearchItems(ByVal searchCategory As SearchCategory, ByVal ParamArray keywords As String()) As List(Of AmazonItem)
            If String.IsNullOrEmpty(Me.ApplicationKey) Then
                Throw New InvalidOperationException(My.Resources.ErrorApplicationKeyNotSet)
            End If

            ' Throw an exception if no keywords were specified
            If keywords Is Nothing OrElse keywords.Length = 0 Then
                Throw New InvalidOperationException(String.Format(CultureInfo.InvariantCulture, My.Resources.ErrorSpecifyArgument, "keyword"))
            End If

            Dim requestUrl As String = Me.GetRequestUrl(searchCategory, Nothing, ItemCondition.None, Nothing, Nothing, GetKeywordString(keywords), Nothing, Nothing, Nothing, Nothing, Nothing)

            ' Get Amazon ItemSearch responses
            Dim responseData As String = MyBase.GetQueryResponse(requestUrl)

            ' Parse the data and return results
            Return Amazon.ParseResponseXml(responseData)
        End Function

        ''' <summary>
        ''' Searches for items based on keyword(s)
        ''' </summary>
        ''' <param name="searchCategory">Search Category</param>
        ''' <param name="condition">Condition of the item</param>
        ''' <param name="minimumPrice">Minimum price (null for default value)</param>
        ''' <param name="maximumPrice">Maximum price (null for default value)</param>
        ''' <param name="keywords">One or more keywords to search for</param>
        ''' <returns>List of Items that match the search criteria</returns>
        ''' <exception cref="InvalidOperationException">The Application Key is not set (OR) the keywords are not specified</exception>
        ''' <exception cref="AmazonException">Amazon Web service has raised an error</exception>
        Public Function SearchItems(ByVal searchCategory As SearchCategory, ByVal condition As ItemCondition, ByVal minimumPrice As Nullable(Of Integer), ByVal maximumPrice As Nullable(Of Integer), ByVal ParamArray keywords As String()) As List(Of AmazonItem)
            If String.IsNullOrEmpty(Me.ApplicationKey) Then
                Throw New InvalidOperationException(My.Resources.ErrorApplicationKeyNotSet)
            End If

            ' Throw an exception if no keywords were specified
            If keywords Is Nothing OrElse keywords.Length = 0 Then
                Throw New InvalidOperationException(String.Format(CultureInfo.InvariantCulture, My.Resources.ErrorSpecifyArgument, "keyword"))
            End If

            Dim requestUrl As String = Me.GetRequestUrl(searchCategory, Nothing, condition, minimumPrice, maximumPrice, GetKeywordString(keywords), Nothing, Nothing, Nothing, Nothing, Nothing)

            ' Get Amazon ItemSearch responses
            Dim responseData As String = MyBase.GetQueryResponse(requestUrl)

            ' Parse the data and return results
            Return Amazon.ParseResponseXml(responseData)
        End Function

		''' <summary>
		''' Searches for items based on the specified search criteria and returns the results in a dataset.
		''' </summary>
		''' <param name="searchCategory">Search Category</param>
		''' <param name="pageNo">Search Results page number (null for default value)</param>
		''' <param name="condition">Condition of the item</param>
		''' <param name="minimumPrice">Minimum price (null for default value)</param>
		''' <param name="maximumPrice">Maximum price (null for default value)</param>
		''' <param name="keywords">One or more keywords to search for</param>
		''' <returns>Dataset containing list of Items that match the search criteria</returns>
		''' <exception cref="InvalidOperationException">The Application Key is not set (OR) the keywords are not specified</exception>
		''' <exception cref="AmazonException">Amazon Web service has raised an error</exception>
		Public Function SearchItems_DS(ByVal searchCategory As SearchCategory, ByVal pageNo As Nullable(Of Integer), ByVal condition As ItemCondition, ByVal minimumPrice As Nullable(Of Integer), ByVal maximumPrice As Nullable(Of Integer), ParamArray ByVal keywords As String()) As DS_Amazon
			Dim amazonItems As List(Of AmazonItem) = SearchItems(searchCategory, pageNo, condition, minimumPrice, maximumPrice, keywords)
			Return PopulateDataset(amazonItems)
		End Function

		''' <summary>
		''' Searches for items based on the specified search criteria and returns the results in a dataset.
		''' </summary>
		''' <param name="searchCategory">Search Category</param>
		''' <param name="keywords">One or more keywords to search for</param>
		''' <returns>Dataset containing list of Items that match the search criteria</returns>
		''' <exception cref="InvalidOperationException">The Application Key is not set (OR) the keywords are not specified</exception>
		''' <exception cref="AmazonException">Amazon Web service has raised an error</exception>
		Public Function SearchItems_DS(ByVal searchCategory As SearchCategory, ParamArray ByVal keywords As String()) As DS_Amazon
			Dim amazonItems As List(Of AmazonItem) = SearchItems(searchCategory, keywords)
			Return PopulateDataset(amazonItems)
		End Function

		''' <summary>
		''' Searches for items based on the specified search criteria and returns the results in a dataset.
		''' </summary>
		''' <param name="searchCategory">Search Category</param>
		''' <param name="condition">Condition of the item</param>
		''' <param name="minimumPrice">Minimum price (null for default value)</param>
		''' <param name="maximumPrice">Maximum price (null for default value)</param>
		''' <param name="keywords">One or more keywords to search for</param>
		''' <returns>Dataset containing list of Items that match the search criteria</returns>
		''' <exception cref="InvalidOperationException">The Application Key is not set (OR) the keywords are not specified</exception>
		''' <exception cref="AmazonException">Amazon Web service has raised an error</exception>
		Public Function SearchItems_DS(ByVal searchCategory As SearchCategory, ByVal condition As ItemCondition, ByVal minimumPrice As Nullable(Of Integer), ByVal maximumPrice As Nullable(Of Integer), ParamArray ByVal keywords As String()) As DS_Amazon
			Dim amazonItems As List(Of AmazonItem) = SearchItems(searchCategory, condition, minimumPrice, maximumPrice, keywords)
			Return PopulateDataset(amazonItems)
		End Function
		#End Region

		#Region "Private functions"

		''' <summary>
		''' Converts the keywords array into a space separated string
		''' </summary>
		''' <param name="keywords">Array of keywords</param>
		''' <returns>String of space separated keywords</returns>
		Private Shared Function GetKeywordString(ParamArray ByVal keywords As String()) As String
			Dim keywordString As StringBuilder = New StringBuilder()
			Dim index As Integer
			For index = 0 To keywords.Length - 2
				If Not keywords(index) Is Nothing AndAlso keywords(index).Trim().Length <> 0 Then
					keywordString.Append(keywords(index).Trim())
					keywordString.Append("%20")
				End If
			Next index

			' Do not put encoded space at the end
			If Not keywords(index) Is Nothing AndAlso keywords(index).Trim().Length <> 0 Then
				keywordString.Append(keywords(index).Trim())
			End If

			Return keywordString.ToString()
		End Function

		''' <summary>
		''' Creates the request url
		''' </summary>
		''' <param name="searchCategory">Search Category</param>
		''' <param name="pageNo">Search Results page number (null for default value)</param>
		''' <param name="condition">Condition of the item</param>
		''' <param name="minimumPrice">Minimum price (null for default value)</param>
		''' <param name="maximumPrice">Maximum price (null for default value)</param>
		''' <param name="keywords">One or more keywords to search for</param>
		''' <param name="title">Title</param>
		''' <param name="artist">Artist</param>
		''' <param name="musicLabel">Music Label</param>
		''' <param name="author">Author</param>
		''' <param name="publisher">Publisher</param>
		''' <returns>Request Url</returns>
		Private Function GetRequestUrl(ByVal searchCategory As SearchCategory, ByVal pageNo As Nullable(Of Integer), ByVal condition As ItemCondition, ByVal minimumPrice As Nullable(Of Integer), ByVal maximumPrice As Nullable(Of Integer), ByVal keywords As String, ByVal title As String, ByVal artist As String, ByVal musicLabel As String, ByVal author As String, ByVal publisher As String) As String
			Dim queryBuilder As StringBuilder = New StringBuilder(Amazon.baseUrl)

			' Add application key
			queryBuilder.Append("&AWSAccessKeyId=" & Me.ApplicationKey)

			' Add search index
			queryBuilder.Append("&SearchIndex=" & searchCategory.ToString())

			' Add page no. if specified
			If pageNo.HasValue Then
				queryBuilder.Append("&ItemPage=" & pageNo.Value)
			End If

			' Add condition if specified
			If condition <> ItemCondition.None Then
				queryBuilder.Append("&Condition=" & condition.ToString())
			End If

			' Add minimum price if specified
			If minimumPrice.HasValue Then
				queryBuilder.Append("&MinimumPrice=" & minimumPrice.Value)
			End If

			' Add maximum price if specified
			If maximumPrice.HasValue Then
				queryBuilder.Append("&MaximumPrice=" & maximumPrice.Value)
			End If

			' Add keywords if specified
			If keywords.Trim().Length <> 0 Then
				queryBuilder.Append("&Keywords=" & keywords.Trim())
			End If

			' Add title if specified
			If (Not String.IsNullOrEmpty(title)) Then
				queryBuilder.Append("&Title=" & title.Trim())
			End If

			' Add artist if specified
			If (Not String.IsNullOrEmpty(artist)) Then
				queryBuilder.Append("&Artist=" & artist.Trim())
			End If

			' Add music label if specified
			If (Not String.IsNullOrEmpty(musicLabel)) Then
				queryBuilder.Append("&MusicLabel=" & musicLabel.Trim())
			End If

			' Add author if specified
			If (Not String.IsNullOrEmpty(author)) Then
				queryBuilder.Append("&Author=" & author.Trim())
			End If

			' Add publisher if specified
			If (Not String.IsNullOrEmpty(publisher)) Then
				queryBuilder.Append("&Publisher=" & publisher.Trim())
			End If

			Return queryBuilder.ToString()
		End Function

		''' <summary>
		''' Parses the response data and extracts the items
		''' </summary>
		''' <param name="responseData">Response data</param>
		''' <returns>List of items</returns>
		Private Shared Function ParseResponseXml(ByVal responseData As String) As List(Of AmazonItem)
			Dim xmlDocument As XmlDocument = New XmlDocument()
			Dim searchResults As List(Of AmazonItem) = Nothing

			Dim nsManager As XmlNamespaceManager = New XmlNamespaceManager(xmlDocument.NameTable)
			Dim amazonNS As String = "http://webservices.amazon.com/AWSECommerceService/2005-10-05"
			nsManager.AddNamespace("amazon", amazonNS)
			xmlDocument.LoadXml(responseData)

			' Retrieve errors nodes
			Dim errorNodes As XmlNodeList = xmlDocument.GetElementsByTagName("Error", amazonNS)
			If errorNodes.Count > 0 Then
				Throw New AmazonException(errorNodes(0).SelectSingleNode("amazon:Code", nsManager).InnerText, errorNodes(0).SelectSingleNode("amazon:Message", nsManager).InnerText)
			End If

			' Retrieve result nodes
			Dim itemNodes As XmlNodeList = xmlDocument.DocumentElement.SelectNodes("amazon:Items/amazon:Item", nsManager)

			If itemNodes.Count = 0 Then
				Return searchResults
			End If

			searchResults = New List(Of AmazonItem)(itemNodes.Count)

			For i As Integer = 0 To itemNodes.Count - 1
				Dim itemNode As XmlNode = itemNodes(i)
				Dim amazonItem As AmazonItem = New AmazonItem()

				' Populate AmazonItem object
				amazonItem.Asin = itemNode.SelectSingleNode("amazon:ASIN", nsManager).InnerText
				amazonItem.Url = itemNode.SelectSingleNode("amazon:DetailPageURL", nsManager).InnerText
				Dim itemAttributesNode As XmlNode = itemNode.SelectSingleNode("amazon:ItemAttributes", nsManager)
				For Each itemAttribute As XmlNode In itemAttributesNode.ChildNodes
					If (Not amazonItem.ItemAttributes.ContainsKey(itemAttribute.Name)) Then
						amazonItem.ItemAttributes.Add(itemAttribute.Name, New ArrayList())
					End If
					amazonItem.ItemAttributes(itemAttribute.Name).Add(itemAttribute.InnerText)
				Next itemAttribute
				searchResults.Add(amazonItem)
			Next i

			Return searchResults
		End Function

		''' <summary>
		''' Returns a dataset populated with the specified Amazon Items.
		''' </summary>
		''' <param name="amazonItems">List of AmazonItem objects</param>
		''' <returns>Dataset containing list of Amazon Items</returns>
		Private Shared Function PopulateDataset(ByVal amazonItems As List(Of AmazonItem)) As DS_Amazon
			Dim dataset As DS_Amazon = New DS_Amazon()

			For Each item As AmazonItem In amazonItems
				Dim amazonItemRow As DS_Amazon.AmazonItemRow = dataset.AmazonItem.AddAmazonItemRow(item.Asin, item.Url)
				For Each itemAttribute As KeyValuePair(Of String, ArrayList) In item.ItemAttributes
					Dim itemAttributeRow As DS_Amazon.ItemAttributeRow = Nothing
					For Each row As DS_Amazon.ItemAttributeRow In dataset.ItemAttribute.Rows
						If row.Name = itemAttribute.Key Then
							itemAttributeRow = row
							Exit For
						End If
					Next row

					If itemAttributeRow Is Nothing Then
						itemAttributeRow = dataset.ItemAttribute.AddItemAttributeRow(itemAttribute.Key)
					End If

					dataset.AmazonItem_ItemAttribute_Relation.AddAmazonItem_ItemAttribute_RelationRow(amazonItemRow, itemAttributeRow)

					For Each itemAttributeValue As String In itemAttribute.Value
						dataset.ItemAttributeValue.AddItemAttributeValueRow(itemAttributeValue, itemAttributeRow.Id, amazonItemRow.Asin)
					Next itemAttributeValue
				Next itemAttribute
			Next item
			Return dataset

		End Function
		#End Region
	End Class

	''' <summary>
	''' Represents an item published on Amazon.com
	''' </summary>
	Public Class AmazonItem
		#Region "Private Members"
		''' <summary>
		''' Item Id
		''' </summary>
		Private asin_Renamed As String

		''' <summary>
		''' Url with the details about the item
		''' </summary>
		Private url_Renamed As String

		''' <summary>
		''' Attributes of the item
		''' </summary>
		Private itemAttributes_Renamed As Dictionary(Of String, ArrayList) = New Dictionary(Of String, ArrayList)()
		#End Region

		#Region "Public Properties"
		''' <summary>
		''' Item Id
		''' </summary>
		Public Property Asin() As String
			Get
				Return Me.asin_Renamed
			End Get
			Set(ByVal value As String)
				Me.asin_Renamed = value
			End Set
		End Property
		''' <summary>
		''' Url with the details about the item
		''' </summary>
		Public Property Url() As String
			Get
				Return Me.url_Renamed
			End Get
			Set(ByVal value As String)
				Me.url_Renamed = value
			End Set
		End Property
		''' <summary>
		''' Attributes of the item
		''' </summary>
		Public ReadOnly Property ItemAttributes() As Dictionary(Of String, ArrayList)
			Get
				Return Me.itemAttributes_Renamed
			End Get
		End Property
		#End Region
	End Class

	''' <summary>
	''' The condition of the items to be returned in the search
	''' </summary>
	Public Enum ItemCondition
		''' <summary>
		''' Represents all items
		''' </summary>
		All

		''' <summary>
		''' Represents new items
		''' </summary>
		[New]

		''' <summary>
		''' Represents used items
		''' </summary>
		Used

		''' <summary>
		''' Represents refurbished items
		''' </summary>
		Refurbished

		''' <summary>
		''' Represents collectible items
		''' </summary>
		Collectible

		''' <summary>
		''' Represents all items
		''' </summary>
		None
	End Enum

	''' <summary>
	''' Search Category
	''' </summary>
	Public Enum SearchCategory
		''' <summary>
		''' Represents search for apparel
		''' </summary>
		Apparel
		''' <summary>
		''' Represents search for automotives
		''' </summary>
		Automotive
		''' <summary>
		''' Represents search for baby products
		''' </summary>
		Baby
		''' <summary>
		''' Represents search for beauty products
		''' </summary>
		Beauty
		''' <summary>
		''' Represents search for any products
		''' </summary>
		Blended
		''' <summary>
		''' Represents search for books
		''' </summary>
		Books
		''' <summary>
		''' Represents search for classical products
		''' </summary>
		Classical
		''' <summary>
		''' Represents search for DVDs
		''' </summary>
		DVD
		''' <summary>
		''' Represents search for digital music
		''' </summary>
		DigitalMusic
		''' <summary>
		''' Represents search for electronics
		''' </summary>
		Electronics
		''' <summary>
		''' Represents search for gourmet food
		''' </summary>
		GourmetFood
		''' <summary>
		''' Represents search for health and personal care products
		''' </summary>
		HealthPersonalCare
		''' <summary>
		''' Represents search for jewelry
		''' </summary>
		Jewelry
		''' <summary>
		''' Represents search for kitchen products
		''' </summary>
		Kitchen
		''' <summary>
		''' Represents search for magazines
		''' </summary>
		Magazines
		''' <summary>
		''' Represents search for market place products
		''' </summary>
		Marketplace
		''' <summary>
		''' Represents search for merchants
		''' </summary>
		Merchants
		''' <summary>
		''' Represents search for miscellaneous items
		''' </summary>
		Miscellaneous
		''' <summary>
		''' Represents search for music
		''' </summary>
		Music
		''' <summary>
		''' Represents search for music tracks
		''' </summary>
		MusicTracks
		''' <summary>
		''' Represents search for musical instruments
		''' </summary>
		MusicalInstruments
		''' <summary>
		''' Represents search for office products
		''' </summary>
		OfficeProducts
		''' <summary>
		''' Represents search for outdoor living products
		''' </summary>
		OutdoorLiving
		''' <summary>
		''' Represents search for PC hardware 
		''' </summary>
		PCHardware
		''' <summary>
		''' Represents search for pet supplies
		''' </summary>
		PetSupplies
		''' <summary>
		''' Represents search for photos
		''' </summary>
		Photo
		''' <summary>
		''' Represents search for restaurants
		''' </summary>
		Restaurants
		''' <summary>
		''' Represents search for software
		''' </summary>
		Software
		''' <summary>
		''' Represents search for sporting goods
		''' </summary>
		SportingGoods
		''' <summary>
		''' Represents search for tools
		''' </summary>
		Tools
		''' <summary>
		''' Represents search for toys
		''' </summary>
		Toys
		''' <summary>
		''' Represents search for VHS
		''' </summary>
		VHS
		''' <summary>
		''' Represents search for video
		''' </summary>
		Video
		''' <summary>
		''' Represents search for video games
		''' </summary>
		VideoGames
		''' <summary>
		''' Represents search for wireless products
		''' </summary>
		Wireless
		''' <summary>
		''' Represents search for wireless accessories
		''' </summary>
		WirelessAccessories
	End Enum

	''' <summary>
	''' Exception Class to handle exceptions
	''' </summary>
	<Global.System.Serializable> _
	Public Class AmazonException
		Inherits Exception
		''' <summary>
		''' Error code from error node
		''' </summary>
		Private errorCode_Renamed As String
		''' <summary>
		''' Required to throw the specific exception
		''' </summary>
		Public Property ErrorCode() As String
			Get
				Return errorCode_Renamed
			End Get
			Set(ByVal value As String)
				Me.errorCode_Renamed = value
			End Set
		End Property
		''' <summary>
		''' Initializes a new object of AmazonException class
		''' </summary>
		Public Sub New()
		End Sub
		''' <summary>
		''' Initializes a new object of AmazonException class
		''' </summary>
		''' <param name="errorCode">The code that represents the error</param>
		''' <param name="message">The message that describes the error</param>
        Public Sub New(ByVal errorCode As String, ByVal message As String)
            MyBase.New(message)
            Me.ErrorCode = errorCode
        End Sub
		''' <summary>
		''' Initializes a new object of AmazonException class
		''' </summary>
		''' <param name="message">The message that describes the error</param>
		Public Sub New(ByVal message As String)
			MyBase.New(message)
		End Sub
		''' <summary>
		''' Initializes a new object of AmazonException class
		''' </summary>
		''' <param name="errorCode">The code that represents the error</param>
		''' <param name="message">The message that describes the error</param>
		''' <param name="inner">The exception that is the cause of the current exception</param>
        Public Sub New(ByVal errorCode As String, ByVal message As String, ByVal inner As Exception)
            MyBase.New(message, inner)
            Me.ErrorCode = errorCode
        End Sub
		''' <summary>
		''' Initializes a new object of AmazonException class
		''' </summary>
		''' <param name="message">The message that describes the error</param>
		''' <param name="inner">The exception that is the cause of the current exception</param>
		Public Sub New(ByVal message As String, ByVal inner As Exception)
			MyBase.New(message, inner)
		End Sub
		''' <summary>
		''' Initializes a new object of AmazonException class
		''' </summary>
		''' <param name="info">The System.Runtime.Serialization.SerializationInfo that holds the serialized
		''' object data about the exception being thrown.</param>
		''' <param name="context">The System.Runtime.Serialization.StreamingContext that contains contextual
		''' information about the source or destination.</param>
		Protected Sub New(ByVal info As SerializationInfo, ByVal context As StreamingContext)
			MyBase.New(info, context)
				Me.ErrorCode = info.GetString("errorCode")
		End Sub
		''' <summary>
		''' Sets the System.Runtime.Serialization.SerializationInfo
		''' with information about the exception.
		''' </summary>
		''' <param name="info">The System.Runtime.Serialization.SerializationInfo that holds the serialized
		''' object data about the exception being thrown.</param>
		''' <param name="context">The System.Runtime.Serialization.StreamingContext that contains contextual
		''' information about the source or destination.</param>
		<SecurityPermissionAttribute(SecurityAction.Demand, SerializationFormatter := True)> _
		Public Overrides Sub GetObjectData(ByVal info As SerializationInfo, ByVal context As StreamingContext)
			info.AddValue("errorCode", Me.ErrorCode)
			MyBase.GetObjectData(info, context)
		End Sub

	End Class
End Namespace
